package com.zyf.controller.api;

import com.zyf.common.result.Result;
import com.zyf.model.hosp.Hospital;
import com.zyf.model.hosp.Schedule;
import com.zyf.service.DepartmentService;
import com.zyf.service.HospitalService;
import com.zyf.service.HospitalSetService;
import com.zyf.service.ScheduleService;
import com.zyf.vo.hosp.DepartmentVo;
import com.zyf.vo.hosp.HospitalQueryVo;
import com.zyf.vo.hosp.ScheduleOrderVo;
import com.zyf.vo.order.SignInfoVo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/** 医院前端数据接口
 * @author zyf
 * @date 2021年05月17日 11:46
 */
@RestController
@RequestMapping("/admin/hosp/hospital")
public class HospApiController {

    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private ScheduleService scheduleService;

    @Autowired
    private HospitalSetService hospitalSetService;

    @ApiOperation(value = "分页条件查询前台医院列表")
    @GetMapping("/findHospList/{page}/{limit}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页"),
            @ApiImplicitParam(name = "limit", value = "每页显示条数，默认 10"),
            @ApiImplicitParam(name = "hospitalSetQueryVo", value = "条件查询实体类")
    })
    public Result findHospList(@PathVariable Integer page,
                               @PathVariable Integer limit,
                               HospitalQueryVo hospitalQueryVo
    ){
        Page<Hospital> hospitals = hospitalService.selectHospByPage(page, limit, hospitalQueryVo);
        return Result.ok(hospitals);
    }

    @ApiOperation(value = "根据医院名称模糊查询医院信息")
    @GetMapping("/findHospByHosName/{hosname}")
    @ApiImplicitParam(name = "hosname", value = "医院名称")
    public Result findHospByHosName(@PathVariable String hosname){
       List<Hospital> list =  hospitalService.findHospByHosName(hosname);
       return Result.ok(list);
    }

    @ApiOperation(value = "根据医院编号获取科室信息")
    @GetMapping("/department/{hoscode}")
    @ApiImplicitParam(name = "hoscode", value = "医院编号")
    public Result getDepartmentByHoscode(@PathVariable String hoscode){
        List<DepartmentVo> deptTree = departmentService.findDeptTree(hoscode);
        return Result.ok(deptTree);
    }

    @ApiOperation(value = "根据医院编号获取医院预约挂号详情")
    @GetMapping("/findHospDetail/{hoscode}")
    @ApiImplicitParam(name = "hoscode", value = "医院编号")
    public Result findHospDetail(@PathVariable String hoscode){
        Map<String,Object> item = hospitalService.item(hoscode);
        return Result.ok(item);
    }

    @ApiOperation(value = "获取可以预约的排班信息")
    @GetMapping("/auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页"),
            @ApiImplicitParam(name = "limit", value = "每页显示条数，默认 10"),
            @ApiImplicitParam(name = "hoscode", value = "医院编号"),
            @ApiImplicitParam(name = "depcode", value = "科室编号"),
    })
    public Result getBookingScheduleRule(@PathVariable Integer page,
                                         @PathVariable Integer limit,
                                         @PathVariable String hoscode,
                                         @PathVariable String depcode
    ){
        Map<String,Object> map = scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode);
        return Result.ok(map);
    }


    @ApiOperation("获取排班数据")
    @GetMapping("/auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "hoscode", value = "医院编号"),
            @ApiImplicitParam(name = "depcode", value = "科室编号"),
            @ApiImplicitParam(name = "workDate", value = "挂号日期")
    })
    public Result findScheduleList(@PathVariable String hoscode,
                                   @PathVariable String depcode,
                                   @PathVariable String workDate
    ){
        List<Schedule> scheduleDetail = scheduleService.getScheduleDetail(hoscode, depcode, workDate);
        return Result.ok(scheduleDetail);
    }

    @ApiOperation(value = "根据排班id获取排班数据")
    @GetMapping("/getSchedule/{scheduleId}")
    @ApiImplicitParam(name = "scheduleId",value = "排班id")
    public Result getSchedule(@PathVariable String scheduleId){
        Schedule schedule = scheduleService.getScheduleById(scheduleId);
        return Result.ok(schedule);
    }

    @ApiOperation(value = "根据排班id，获取预约挂号下单数据")
    @GetMapping("/inner/getScheduleOrderVo/{scheduleId}")
    @ApiImplicitParam(name = "scheduleId",value = "排班id")
    public ScheduleOrderVo getScheduleOrderVo(@PathVariable("scheduleId") String scheduleId){
        ScheduleOrderVo scheduleOrderVo = scheduleService.getScheduleOrderVo(scheduleId);
        return scheduleOrderVo;
    }

    @ApiOperation(value = "根据医院编号，获取医院的签名信息")
    @GetMapping("/inner/getSignInfoVo/{hoscode}")
    @ApiImplicitParam(name = "hoscode",value = "医院编号")
    public SignInfoVo getSignInfoVo(@PathVariable("hoscode") String hoscode){
        SignInfoVo signInfoVo = hospitalSetService.getSignInfoVo(hoscode);
        return signInfoVo;
    }
}
